package it.tcon.xbeedriver;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import com.rapplogic.xbee.api.XBeeAddress64;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

public class testXMLfileSaving {
	public static void main(String[] args){
		
		
		int[] a1 = null;
		int b1 = 1002;
		a1 = new int[]{b1};
		
		XBeeNode node1 = new XBeeNode(new XBeeAddress64(0,0,0,0,0,0,0,0));
		XBeeNode node2 = new XBeeNode(new XBeeAddress64(0,0,0,0,0,0,1,0));
		XBeeNode node3 = new XBeeNode(new XBeeAddress64(0,0,0,0,0,0,2,0));
		XBeeNode node4 = new XBeeNode(new XBeeAddress64(0,0,0,0,0,0,3,0));
		//test2 root = new test2();
		XStream xs = new XStream();
		
		try {
			FileOutputStream fs = new FileOutputStream("test.dat");
			ObjectOutputStream out = xs.createObjectOutputStream(fs);
			
			out.writeObject(node1);
			out.writeObject(node2);
			out.writeObject(node3);
			out.writeObject(node4);

			out.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		try{
			XStream inxs = new XStream(new DomDriver());
			FileInputStream fi = new FileInputStream("test.dat");
			ObjectInputStream in = inxs.createObjectInputStream(fi);
			
			//XBeeNode node = new XBeeNode();
			XBeeNode a = (XBeeNode) in.readObject();
			XBeeNode b = (XBeeNode) in.readObject();
			//XBeeNode c = (XBeeNode) in.readObject();
			//XBeeNode d = (XBeeNode) in.readObject();
			//node = (XBeeNode) in.fromXML(fi,root);
			System.out.println("nodo: "+a.getAddress64String()+" 2 "+b.getAddress64String());
			
		}
		catch (Exception e){
			e.printStackTrace();
		}
		
		
	}
}
